Answer:

No. The + is not allowed, at least not in Java 1.5.0_06. This is weird, and may change with the next release of Java.

Another Example

Here is another example. It asks the user for two integers which are then added together and the sum written out.

import java.util.Scanner;

class AddTwo
{
  public static void main (String[] args) 
  { 
    Scanner scan = new Scanner( System.in );
    int first, second, sum ;      // declaration of int variables

    System.out.println("Enter first  integer:");
    first = scan.nextInt();       // read chars and convert to int

    System.out.println("Enter second integer:");
    second = scan.nextInt();      // read chars and convert to int

    sum = first + second;         // add the two ints, put result in sum

    System.out.println("The sum of " + 
        first + " plus " + second +" is " + sum );
  }
}

Here is a sample run:

Enter first  integer:
12
Enter second integer:
-8
The sum of 12 plus -8 is 4

QUESTION 15:

(A slightly hard question: ) explain what happened in the following run of the same program:

Enter first  integer:
12 -8
Enter second integer:
The sum of 12 plus -8 is 4